home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
681
/
term
/
source.lha
/
Scale.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
8KB
|
427 lines
/*
** $Id: Scale.c,v 1.3 92/05/01 12:52:56 olsen Sta Locker: olsen $
** $Revision: 1.3 $
** $Date: 92/05/01 12:52:56 $
**
** Single scaled character output routines
**
** Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
/* Some static data required by the bitmap scaling routine. */
STATIC struct RastPort *ScaleRPort;
STATIC struct BitMap *ScaleSrcBitMap,
*ScaleDstBitMap;
STATIC struct BitScaleArgs *ScaleArgs;
STATIC WORD ScaleCache = -1;
/* DeleteScale():
*
* Frees all the data associated with font scaling.
*/
VOID
DeleteScale()
{
if(ScaleArgs)
{
FreeVec(ScaleArgs);
ScaleArgs = NULL;
}
if(ScaleDstBitMap)
{
if(ScaleDstBitMap -> Planes[0])
FreeVec(ScaleDstBitMap -> Planes[0]);
FreeVec(ScaleDstBitMap);
ScaleDstBitMap = NULL;
}
if(ScaleSrcBitMap)
{
if(ScaleSrcBitMap -> Planes[0])
FreeVec(ScaleSrcBitMap -> Planes[0]);
FreeVec(ScaleSrcBitMap);
ScaleSrcBitMap = NULL;
}
if(ScaleRPort)
{
FreeVec(ScaleRPort);
ScaleRPort = NULL;
}
}
/* CreateScale():
*
* Sets up the data required for real-time font scaling
* (bitmaps, rastports, etc.).
*/
BYTE
CreateScale()
{
WORD i;
/* Create a RastPort to render into. */
if(ScaleRPort = (struct RastPort *)AllocVec(sizeof(struct RastPort),MEMF_ANY|MEMF_CLEAR))
{
/* Initialize it. */
InitRastPort(ScaleRPort);
/* Create the bitmap to render into. */
if(ScaleSrcBitMap = (struct BitMap *)AllocVec(sizeof(struct BitMap),MEMF_ANY|MEMF_CLEAR))
{
/* Initialize the bitmap. */
InitBitMap(ScaleSrcBitMap,Screen -> RastPort . BitMap -> Depth,8,8);
/* Create the bitmap to place the scaled font data into. */
if(ScaleDstBitMap = (struct BitMap *)AllocVec(sizeof(struct BitMap),MEMF_ANY|MEMF_CLEAR))
{
/* Initialize it, must be able to hold four
* times the size of the source data.
*/
InitBitMap(ScaleDstBitMap,Screen -> RastPort . BitMap -> Depth,16,16);
/* Put the source bitmap into the source RastPort. */
ScaleRPort -> BitMap = ScaleSrcBitMap;
/* Allocate the necessary memory space. */
if(ScaleSrcBitMap -> Planes[0] = (PLANEPTR)AllocVec(ScaleSrcBitMap -> BytesPerRow * ScaleSrcBitMap -> Rows * ScaleSrcBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
{
/* Fill in the planes. */
for(i = 1 ; i < ScaleSrcBitMap -> Depth ; i++)
ScaleSrcBitMap -> Planes[i] = ScaleSrcBitMap -> Planes[i - 1] + ScaleSrcBitMap -> BytesPerRow * ScaleSrcBitMap -> Rows;
/* Allocate space for the destination area. */
if(ScaleDstBitMap -> Planes[0] = (PLANEPTR)AllocVec(ScaleDstBitMap -> BytesPerRow * ScaleDstBitMap -> Rows * ScaleDstBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
{
/* Fill in the remaining planes. */
for(i = 1 ; i < ScaleDstBitMap -> Depth ; i++)
ScaleDstBitMap -> Planes[i] = ScaleDstBitMap -> Planes[i - 1] + ScaleDstBitMap -> BytesPerRow * ScaleDstBitMap -> Rows;
/* Install the fonts. */
SetFont(ScaleRPort,CurrentFont);
/* Set the default rendering pens. */
SetAPen(ScaleRPort,1);
SetBPen(ScaleRPort,0);
/* By default, overwrite data. */
SetDrMd(ScaleRPort,JAM2);
/* Allocate space for the bitmap scaling arguments. */
if(ScaleArgs = (struct BitScaleArgs *)AllocVec(sizeof(struct BitScaleArgs),MEMF_ANY|MEMF_CLEAR))
{
/* Initialize the structure. */
ScaleArgs -> bsa_SrcWidth = 8;
ScaleArgs -> bsa_SrcHeight = 8;
ScaleArgs -> bsa_YSrcFactor = 1;
ScaleArgs -> bsa_SrcBitMap = ScaleSrcBitMap;
ScaleArgs -> bsa_DestBitMap = ScaleDstBitMap;
return(TRUE);
}
}
}
}
}
}
return(FALSE);
}
/* PrintScaled(UBYTE Char,UBYTE Scale):
*
* This is the big one: since VT100 supports a number of
* font sizes (double height, double width, 132 columns),
* the approriate characters are scaled in real-time before
* they are displayed.
*/
VOID __regargs
PrintScaled(UBYTE *Buffer,LONG Size,UBYTE Scale)
{
UWORD SrcY,DestX,DestY,SizeX,Baseline;
/* Determine the scale of the destination character. */
if(Config . FontScale == SCALE_HALF)
{
/* Determine scale to be used. */
switch(Scale)
{
/* Half width. */
case SCALE_ATTR_NORMAL:
ScaleArgs -> bsa_XDestFactor = 1;
ScaleArgs -> bsa_YDestFactor = 1;
ScaleArgs -> bsa_XSrcFactor = 2;
SrcY = 0;
DestX = CursorX * 4;
SizeX = 4;
ScaleCache = -1;
break;
/* Half width, double height (top bits). */
case SCALE_ATTR_TOP2X:
ScaleArgs -> bsa_XDestFactor = 1;
ScaleArgs -> bsa_YDestFactor = 2;
ScaleArgs -> bsa_XSrcFactor = 1;
SrcY = 0;
DestX = CursorX * 8;
SizeX = 8;
ScaleCache = -1;
break;
/* Half width, double height (bottom bits). */
case SCALE_ATTR_BOT2X:
ScaleArgs -> bsa_XDestFactor = 1;
ScaleArgs -> bsa_YDestFactor = 2;
ScaleArgs -> bsa_XSrcFactor = 1;
SrcY = 8;
DestX = CursorX * 8;
SizeX = 8;
ScaleCache = -1;
break;
}
}
else
{
/* Determine scale to be used. */
switch(Scale)
{
/* Double height (top bits). */
case SCALE_ATTR_TOP2X:
ScaleArgs -> bsa_XDestFactor = 2;
ScaleArgs -> bsa_YDestFactor = 2;
ScaleArgs -> bsa_XSrcFactor = 1;
SrcY = 0;
DestX = CursorX * 16;
SizeX = 16;
ScaleCache = -1;
break;
/* Double height (bottom bits). */
case SCALE_ATTR_BOT2X:
ScaleArgs -> bsa_XDestFactor = 2;
ScaleArgs -> bsa_YDestFactor = 2;
ScaleArgs -> bsa_XSrcFactor = 1;
SrcY = 8;
DestX = CursorX * 16;
SizeX = 16;
ScaleCache = -1;
break;
/* Double width. */
case SCALE_ATTR_2X:
ScaleArgs -> bsa_XDestFactor = 2;
ScaleArgs -> bsa_YDestFactor = 1;
ScaleArgs -> bsa_XSrcFactor = 1;
SrcY = 0;
DestX = CursorX * 16;
SizeX = 16;
ScaleCache = -1;
break;
}
}
/* Look for the font type to scale. */
if(ScaleRPort -> Font != CurrentFont)
{
SetFont(ScaleRPort,CurrentFont);
ScaleCache = -1;
}
/* Set the approriate colours. */
if(ScaleRPort -> FgPen != RPort -> FgPen)
{
SetAPen(ScaleRPort,RPort -> FgPen);
ScaleCache = -1;
}
if(ScaleRPort -> BgPen != RPort -> BgPen)
{
SetBPen(ScaleRPort,RPort -> BgPen);
ScaleCache = -1;
}
/* Calculate topmost line to write to. */
DestY = CursorY * 8;
/* Remember the font baseline. */
Baseline = CurrentFont -> tf_Baseline;
if(CurrentFont == GFX)
{
BYTE Mode = 1;
/* Run down the buffer... */
while(Size--)
{
if(GfxTable[*Buffer] == Mode)
{
if(*Buffer != ScaleCache)
{
ScaleCache = *Buffer;
/* Print the character to be scaled into the
* invisible drawing area.
*/
Move(ScaleRPort,0,Baseline);
Text(ScaleRPort,Buffer++,1);
/* Scale the font. */
BitMapScale(ScaleArgs);
}
else
Buffer++;
/* Render the character. */
BltBitMapRastPort(ScaleDstBitMap,0,SrcY,RPort,DestX,DestY,SizeX,8,0xC0);
}
else
{
ScaleCache = *Buffer;
if(Mode)
{
if(Config . Font == FONT_IBM && IBM)
SetFont(ScaleRPort,IBM);
else
SetFont(ScaleRPort,Topaz);
}
else
SetFont(ScaleRPort,GFX);
Mode ^= 1;
/* Print the character to be scaled into the
* invisible drawing area.
*/
Move(ScaleRPort,0,Baseline);
Text(ScaleRPort,Buffer++,1);
/* Scale the font. */
BitMapScale(ScaleArgs);
/* Render the character. */
BltBitMapRastPort(ScaleDstBitMap,0,SrcY,RPort,DestX,DestY,SizeX,8,0xC0);
}
DestX += SizeX;
}
if(!Mode)
SetFont(ScaleRPort,GFX);
}
else
{
/* Run down the buffer... */
while(Size--)
{
if(*Buffer != ScaleCache)
{
ScaleCache = *Buffer;
/* Print the character to be scaled into the
* invisible drawing area.
*/
Move(ScaleRPort,0,Baseline);
Text(ScaleRPort,Buffer++,1);
/* Scale the font. */
BitMapScale(ScaleArgs);
}
else
Buffer++;
/* Render the character. */
BltBitMapRastPort(ScaleDstBitMap,0,SrcY,RPort,DestX,DestY,SizeX,8,0xC0);
DestX += SizeX;
}
}
}